/**
 * Generated Driver File
 * 
 * @file pins.c
 * 
 * @ingroup  pinsdriver
 * 
 * @brief This is generated driver implementation for pins. 
 *        This file provides implementations for pin APIs for all pins selected in the GUI.
 *
 * @version Driver Version 1.1.0
*/

/*
? [2023] Microchip Technology Inc. and its subsidiaries.

    Subject to your compliance with these terms, you may use Microchip 
    software and any derivatives exclusively with Microchip products. 
    You are responsible for complying with 3rd party license terms  
    applicable to your use of 3rd party software (including open source  
    software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? 
    NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS 
    SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,  
    MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 
    WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY 
    KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF 
    MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE 
    FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S 
    TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT 
    EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR 
    THIS SOFTWARE.
*/

#include "../pins.h"
#include "../../../app/hardware.h"

//static void (*AC_InterruptHandler)(void);
//static void (*VDD_InterruptHandler)(void);
//static void (*VCHARGER_InterruptHandler)(void);
//static void (*ICHARGER_InterruptHandler)(void);
//static void (*BAT_InterruptHandler)(void);
//static void (*IOUT_InterruptHandler)(void);
//static void (*DACV_InterruptHandler)(void);
//static void (*RX_InterruptHandler)(void);
//static void (*TX_InterruptHandler)(void);
static void (*OCP_InterruptHandler)(void);
//static void (*VOUT_InterruptHandler)(void);
//static void (*RT_InterruptHandler)(void);
//static void (*BAT_M_InterruptHandler)(void);
//static void (*TIGER_InterruptHandler)(void);
//static void (*ON_CHARGER_InterruptHandler)(void);
//static void (*MAINOFF_InterruptHandler)(void);
//static void (*BATOFF_InterruptHandler)(void);
//static void (*BAT_LOSS_InterruptHandler)(void);
//static void (*SHORT_TEST_InterruptHandler)(void);
//static void (*DIR_485_InterruptHandler)(void);

void PIN_MANAGER_Initialize()
{
  /* OUT Registers Initialization */
    PORTA.OUT = 0x0;
    PORTB.OUT = 0x24;
    PORTC.OUT = 0x0;
    
  /* DIR Registers Initialization */
    PORTA.DIR = 0xE0;
    PORTB.DIR = 0x85;
    PORTC.DIR = 0x11;

  

  /* PINxCTRL registers Initialization */
    PORTA.PIN0CTRL = 0x0;
    PORTA.PIN1CTRL = 0x4;
    PORTA.PIN2CTRL = 0x4;
    PORTA.PIN3CTRL = 0x4;
    PORTA.PIN4CTRL = 0x4;
    PORTA.PIN5CTRL = 0x0;
    PORTA.PIN6CTRL = 0x4;
    PORTA.PIN7CTRL = 0x0;
    PORTB.PIN0CTRL = 0x0;
    PORTB.PIN1CTRL = 0x4;
    PORTB.PIN2CTRL = 0x0;
    PORTB.PIN3CTRL = 0x0;
    PORTB.PIN4CTRL = 0x4;
    PORTB.PIN5CTRL = 0x0;
    PORTB.PIN6CTRL = 0x4;
    PORTB.PIN7CTRL = 0x0;
    PORTC.PIN0CTRL = 0x0;
    PORTC.PIN1CTRL = 0x4;
    PORTC.PIN2CTRL = 0x4;
    PORTC.PIN3CTRL = 0x4;
    PORTC.PIN4CTRL = 0x0;
    PORTC.PIN5CTRL = 0x0;
    PORTC.PIN6CTRL = 0x0;
    PORTC.PIN7CTRL = 0x0;

  /* PORTMUX Initialization */
    PORTMUX.CTRLA = 0x0;
    PORTMUX.CTRLB = 0x0;
    PORTMUX.CTRLC = 0x0;
    PORTMUX.CTRLD = 0x0;

  // register default ISC callback functions at runtime; use these methods to register a custom function
//    AC_SetInterruptHandler(AC_DefaultInterruptHandler);
//    VDD_SetInterruptHandler(VDD_DefaultInterruptHandler);
//    VCHARGER_SetInterruptHandler(VCHARGER_DefaultInterruptHandler);
//    ICHARGER_SetInterruptHandler(ICHARGER_DefaultInterruptHandler);
//    BAT_SetInterruptHandler(BAT_DefaultInterruptHandler);
//    IOUT_SetInterruptHandler(IOUT_DefaultInterruptHandler);
//    DACV_SetInterruptHandler(DACV_DefaultInterruptHandler);
//    RX_SetInterruptHandler(RX_DefaultInterruptHandler);
//    TX_SetInterruptHandler(TX_DefaultInterruptHandler);
    OCP_SetInterruptHandler(OCP_DefaultInterruptHandler);
//    VOUT_SetInterruptHandler(VOUT_DefaultInterruptHandler);
//    RT_SetInterruptHandler(RT_DefaultInterruptHandler);
//    BAT_M_SetInterruptHandler(BAT_M_DefaultInterruptHandler);
//    TIGER_SetInterruptHandler(TIGER_DefaultInterruptHandler);
//    ON_CHARGER_SetInterruptHandler(ON_CHARGER_DefaultInterruptHandler);
//    MAINOFF_SetInterruptHandler(MAINOFF_DefaultInterruptHandler);
//    BATOFF_SetInterruptHandler(BATOFF_DefaultInterruptHandler);
//    BAT_LOSS_SetInterruptHandler(BAT_LOSS_DefaultInterruptHandler);
//    SHORT_TEST_SetInterruptHandler(SHORT_TEST_DefaultInterruptHandler);
//    DIR_485_SetInterruptHandler(DIR_485_DefaultInterruptHandler);
}

/**
  Allows selecting an interrupt handler for AC at application runtime
*/
//void AC_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    AC_InterruptHandler = interruptHandler;
//}
//
//void AC_DefaultInterruptHandler(void)
//{
//    // add your AC interrupt custom code
//    // or set custom function using AC_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for VDD at application runtime
//*/
//void VDD_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    VDD_InterruptHandler = interruptHandler;
//}
//
//void VDD_DefaultInterruptHandler(void)
//{
//    // add your VDD interrupt custom code
//    // or set custom function using VDD_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for VCHARGER at application runtime
//*/
//void VCHARGER_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    VCHARGER_InterruptHandler = interruptHandler;
//}
//
//void VCHARGER_DefaultInterruptHandler(void)
//{
//    // add your VCHARGER interrupt custom code
//    // or set custom function using VCHARGER_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for ICHARGER at application runtime
//*/
//void ICHARGER_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    ICHARGER_InterruptHandler = interruptHandler;
//}
//
//void ICHARGER_DefaultInterruptHandler(void)
//{
//    // add your ICHARGER interrupt custom code
//    // or set custom function using ICHARGER_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for BAT at application runtime
//*/
//void BAT_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    BAT_InterruptHandler = interruptHandler;
//}
//
//void BAT_DefaultInterruptHandler(void)
//{
//    // add your BAT interrupt custom code
//    // or set custom function using BAT_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for IOUT at application runtime
//*/
//void IOUT_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    IOUT_InterruptHandler = interruptHandler;
//}
//
//void IOUT_DefaultInterruptHandler(void)
//{
//    // add your IOUT interrupt custom code
//    // or set custom function using IOUT_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for DACV at application runtime
//*/
//void DACV_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    DACV_InterruptHandler = interruptHandler;
//}
//
//void DACV_DefaultInterruptHandler(void)
//{
//    // add your DACV interrupt custom code
//    // or set custom function using DACV_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for RX at application runtime
//*/
//void RX_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    RX_InterruptHandler = interruptHandler;
//}
//
//void RX_DefaultInterruptHandler(void)
//{
//    // add your RX interrupt custom code
//    // or set custom function using RX_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for TX at application runtime
//*/
//void TX_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    TX_InterruptHandler = interruptHandler;
//}
//
//void TX_DefaultInterruptHandler(void)
//{
//    // add your TX interrupt custom code
//    // or set custom function using TX_SetInterruptHandler()
//}
/**
  Allows selecting an interrupt handler for OCP at application runtime
*/
void OCP_SetInterruptHandler(void (* interruptHandler)(void)) 
{
    OCP_InterruptHandler = interruptHandler;
}

void OCP_DefaultInterruptHandler(void)
{
    // add your OCP interrupt custom code
    // or set custom function using OCP_SetInterruptHandler()
    SCP_HandleIsrCb();
}
/**
  Allows selecting an interrupt handler for VOUT at application runtime
*/
//void VOUT_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    VOUT_InterruptHandler = interruptHandler;
//}
//
//void VOUT_DefaultInterruptHandler(void)
//{
//    // add your VOUT interrupt custom code
//    // or set custom function using VOUT_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for RT at application runtime
//*/
//void RT_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    RT_InterruptHandler = interruptHandler;
//}
//
//void RT_DefaultInterruptHandler(void)
//{
//    // add your RT interrupt custom code
//    // or set custom function using RT_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for BAT_M at application runtime
//*/
//void BAT_M_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    BAT_M_InterruptHandler = interruptHandler;
//}
//
//void BAT_M_DefaultInterruptHandler(void)
//{
//    // add your BAT_M interrupt custom code
//    // or set custom function using BAT_M_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for TIGER at application runtime
//*/
//void TIGER_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    TIGER_InterruptHandler = interruptHandler;
//}
//
//void TIGER_DefaultInterruptHandler(void)
//{
//    // add your TIGER interrupt custom code
//    // or set custom function using TIGER_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for ON_CHARGER at application runtime
//*/
//void ON_CHARGER_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    ON_CHARGER_InterruptHandler = interruptHandler;
//}
//
//void ON_CHARGER_DefaultInterruptHandler(void)
//{
//    // add your ON_CHARGER interrupt custom code
//    // or set custom function using ON_CHARGER_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for MAINOFF at application runtime
//*/
//void MAINOFF_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    MAINOFF_InterruptHandler = interruptHandler;
//}
//
//void MAINOFF_DefaultInterruptHandler(void)
//{
//    // add your MAINOFF interrupt custom code
//    // or set custom function using MAINOFF_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for BATOFF at application runtime
//*/
//void BATOFF_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    BATOFF_InterruptHandler = interruptHandler;
//}
//
//void BATOFF_DefaultInterruptHandler(void)
//{
//    // add your BATOFF interrupt custom code
//    // or set custom function using BATOFF_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for BAT_LOSS at application runtime
//*/
//void BAT_LOSS_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    BAT_LOSS_InterruptHandler = interruptHandler;
//}
//
//void BAT_LOSS_DefaultInterruptHandler(void)
//{
//    // add your BAT_LOSS interrupt custom code
//    // or set custom function using BAT_LOSS_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for SHORT_TEST at application runtime
//*/
//void SHORT_TEST_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    SHORT_TEST_InterruptHandler = interruptHandler;
//}
//
//void SHORT_TEST_DefaultInterruptHandler(void)
//{
//    // add your SHORT_TEST interrupt custom code
//    // or set custom function using SHORT_TEST_SetInterruptHandler()
//}
///**
//  Allows selecting an interrupt handler for DIR_485 at application runtime
//*/
//void DIR_485_SetInterruptHandler(void (* interruptHandler)(void)) 
//{
//    DIR_485_InterruptHandler = interruptHandler;
//}
//
//void DIR_485_DefaultInterruptHandler(void)
//{
//    // add your DIR_485 interrupt custom code
//    // or set custom function using DIR_485_SetInterruptHandler()
//}
ISR(PORTA_PORT_vect)
{ 
    // Call the interrupt handler for the callback registered at runtime
//    if(VPORTA.INTFLAGS & PORT_INT1_bm)
//    {
//       AC_InterruptHandler(); 
//    }
//    if(VPORTA.INTFLAGS & PORT_INT2_bm)
//    {
//       VDD_InterruptHandler(); 
//    }
//    if(VPORTA.INTFLAGS & PORT_INT3_bm)
//    {
//       VCHARGER_InterruptHandler(); 
//    }
//    if(VPORTA.INTFLAGS & PORT_INT4_bm)
//    {
//       ICHARGER_InterruptHandler(); 
//    }
//    if(VPORTA.INTFLAGS & PORT_INT6_bm)
//    {
//       DACV_InterruptHandler(); 
//    }
//    if(VPORTA.INTFLAGS & PORT_INT5_bm)
//    {
//       ON_CHARGER_InterruptHandler(); 
//    }
//    if(VPORTA.INTFLAGS & PORT_INT7_bm)
//    {
//       MAINOFF_InterruptHandler(); 
//    }
    /* Clear interrupt flags */
    VPORTA.INTFLAGS = 0xff;
}

ISR(PORTB_PORT_vect)
{ 
    // Call the interrupt handler for the callback registered at runtime
//    if(VPORTB.INTFLAGS & PORT_INT1_bm)
//    {
//       BAT_InterruptHandler(); 
//    }
//    if(VPORTB.INTFLAGS & PORT_INT4_bm)
//    {
//       IOUT_InterruptHandler(); 
//    }
//    if(VPORTB.INTFLAGS & PORT_INT3_bm)
//    {
//       RX_InterruptHandler(); 
//    }
//    if(VPORTB.INTFLAGS & PORT_INT2_bm)
//    {
//       TX_InterruptHandler(); 
//    }
    if(VPORTB.INTFLAGS & PORT_INT5_bm)
    {
       OCP_InterruptHandler(); 
    }
//    if(VPORTB.INTFLAGS & PORT_INT0_bm)
//    {
//       BATOFF_InterruptHandler(); 
//    }
//    if(VPORTB.INTFLAGS & PORT_INT7_bm)
//    {
//       BAT_LOSS_InterruptHandler(); 
//    }
    /* Clear interrupt flags */
    VPORTB.INTFLAGS = 0xff;
}

ISR(PORTC_PORT_vect)
{ 
    // Call the interrupt handler for the callback registered at runtime
//    if(VPORTC.INTFLAGS & PORT_INT1_bm)
//    {
//       VOUT_InterruptHandler(); 
//    }
//    if(VPORTC.INTFLAGS & PORT_INT2_bm)
//    {
//       RT_InterruptHandler(); 
//    }
//    if(VPORTC.INTFLAGS & PORT_INT3_bm)
//    {
//       BAT_M_InterruptHandler(); 
//    }
//    if(VPORTC.INTFLAGS & PORT_INT5_bm)
//    {
//       TIGER_InterruptHandler(); 
//    }
//    if(VPORTC.INTFLAGS & PORT_INT0_bm)
//    {
//       SHORT_TEST_InterruptHandler(); 
//    }
//    if(VPORTC.INTFLAGS & PORT_INT4_bm)
//    {
//       DIR_485_InterruptHandler(); 
//    }
    /* Clear interrupt flags */
    VPORTC.INTFLAGS = 0xff;
}

/**
 End of File
*/